﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MedicineTracker.Model;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace MedicineTracker.ViewModel
{
    public class TreatmentSiteViewModel: Database, INotifyPropertyChanged
    {
        private ObservableCollection<TreatmentSite> _treatmentSites;

        public ObservableCollection<TreatmentSite> TreatmentSites
        {
            get { return _treatmentSites; }
        }

        public TreatmentSiteViewModel()
        {
            _treatmentSites = new ObservableCollection<TreatmentSite>();
            using (Connection)
            {
                try
                {
                    Connection.Open();
                    Command.CommandText = "SELECT * FROM treatment_sites";
                    Command.Connection = Connection;
                    DataReader = Command.ExecuteReader();
                    while (DataReader.Read())
                    {
                        _treatmentSites.Add(new TreatmentSite
                        {
                            ID = Convert.ToInt32(DataReader["id"]),
                            Description = (string)DataReader["description"]
                        });
                    }
                }
                catch
                {
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
